package euler.p051_100;

import java.math.BigInteger;

import euler.MainEuler;
import euler.helper.NaturalHelper;

public class Euler056 extends MainEuler {
    /*
        A googol (10^100) is a massive number:
        one followed by one-hundred zeros;
        100^100 is almost unimaginably large:
        one followed by two-hundred zeros.

        Despite their size, the sum of the digits
        in each number is only 1.

        Considering natural numbers of the form,
        a^b, where a, b < 100,
        what is the maximum digital sum?

     */
    public String resolve() {
        int limite = 100;

        int maximaSuma = 0;

        for (int a = 0; a < limite; a++) {
            BigInteger potencia = BigInteger.ONE;
            BigInteger exp = BigInteger.valueOf(a);
            for (int b = 0; b < limite; b++) {
                if (NaturalHelper.cantidadDigitos(potencia, 10) * 9 > maximaSuma) {
                    int suma = NaturalHelper.sumaDigital(potencia);

                    if (suma > maximaSuma) {
                        maximaSuma = suma;
                    }
                }
                potencia = potencia.multiply(exp);
            }
        }

        return String.valueOf(maximaSuma);
        // 972
    }



}
